home *** CD-ROM | disk | FTP | other *** search
Wrap
/* Binary Batch Post */ /* NewsRog ARexx Script */ /* A script for easily posting multiple binary files to newsgroups */ /* Copyright © 2000 - 2001 Duncan Taylor */ /* duncan@hiarchive.f9.co.uk */ /* Version 1.2 (21-Jul-2001) */ /* **************** NOTE **************************/ /* As the following cannot be set via ARexx, you must configure NewsRog */ /* Line Wrap option must be turned OFF */ /* "Program Options/Post Options" "Post Wrap Mode" = Never */ /* The following Custom Headers are required */ /* HEADER VALUE MODE GROUP PATT */ /* Content-Type: Multipart/Mixed; Boundary=NewsRog-Boundary-2000 Any *.binaries.* */ /* Content-Transfer-Encoding 7Bit Any *.binaries.* */ /* Content-Disposition: Inline Any *.binaries.* */ /*************** REQUIREMENTS *********************/ /* NewsRog (Version 1.8b) */ /* rexxreqtools.library (Aminet /util/rexx/RexxReqTools.lha) */ /* Base 64 Encoder. This script is configured to use: */ /* Base64Encode (Aminet /comm/mail/Base64Coders.lha) */ /* Although it should be possible to configure the script to use a */ /* different Base 64 Encoder... */ /* MrSPLIT for use with Multipart Binary posts */ /* (Aminet /util/cli/MrSPLIT.lha) */ /* You could use a different split program, but it would mean changing */ /* parts of this script - so only try it if you know what you're doing :) */ /*************************************************/ /* Allow commands to return results */ options results /* Deal with errors */ options failat 21 /* BEGIN PROGRAM */ /****************************************************************/ /****** SET VARIOUS PATHS - YOU MUST CHANGE THESE VALUES *******/ /****************************************************************/ newsrog_path = 'System:Netware/NewsRog/NewsRog' temp_path = 'T:' /* This must include the trailing / if it ends with a directory */ sig_path = 'YAM:.signature' base64_path = 'C:Base64Encode' base64_args = 'NOHEADER' split_path = 'C:MrSPLIT' default_binary_path = 'Internet:Web/TVCaptures' /* No need for the trailing / */ /****************************************************************/ /* Initialisation */ NEWS_PORT = 'NEWSROG' title = ' Binary Batch Post by Duncan Taylor (21-Jul-2001) ' subject_text = ' Enter Subject. The filename will be added automatically ' group_text = ' Enter Group to post to ' body_text = ' Enter text to be include in the body of the message.' '0a'X , ' The filename and total number of files will be added automatically ' files_text = ' Select binary files to post ' body_file_text = ' Select text file to include in body of message ' contact_query = ' Do you want to post Contact Sheets (Thumbnail Indexes)? ' contact_text = ' Select Contact Sheets ' mime_text = ' Enter MIME type for binary files ' post_query = ' Do want want to post artciles now or later? ' online_query = ' NewsRog is not currently Online ' offline_text = ' NewsRog cannot go Online now ' newsrog_error_text = ' Unable to launch NewsRog ' ok_buttons = 'OK' y_or_n_buttons = '_Yes | _No ' /* Check if rexxreqtools.library/rexxsupport.library is installed */ IF ~EXISTS('Libs:rexxreqtools.library') then CALL library_error() IF ~EXISTS('Libs:rexxsupport.library') then CALL library_error() /* Add rexxreqtools.library/rexxsupport.library to functions */ IF ~SHOW('L','rexxreqtools.library') then ADDLIB('rexxreqtools.library', 0, -30, 0) IF ~SHOW('L','rexxsupport.library') then ADDLIB('rexxsupport.library', 0, -30, 0) /* Check config */ IF ~EXISTS(newsrog_path) THEN CALL newsrog_path_error() IF ~EXISTS(temp_path) THEN CALL temp_path_error() IF ~EXISTS(base64_path) THEN CALL base64_path_error() /* If NewsRog isn't running, try to lauch it */ IF ~SHOW('P',NEWS_PORT) THEN DO ADDRESS COMMAND 'RUN >NIL:' newsrog_path 'SYS:REXXC/WaitForPort' NEWS_PORT IF RC>0 THEN DO newsrog_error = RTEZREQUEST(newsrog_error_text,ok_buttons,title,,) IF newsrog_error=0 THEN EXIT END END /* Open Post Queue window */ ADDRESS (NEWS_PORT) ISWINDOWOPEN POSTS IF RC=0 THEN OPENWINDOW POSTS /* Create posts */ /* Determine number of subscribed newsgroups */ GROUPCOUNT NUMBER_GROUPS = result GETGROUP 0 GROUP_0 = result /* Determine names of subscribed newsgroups */ DO j=1 to NUMBER_GROUPS GETGROUP j-1 GROUP_NAME.j = result END /* Select binary newsgroups */ BINARY_GROUPS = 0 DO k=1 to NUMBER_GROUPS binary = INDEX(GROUP_NAME.k, 'binaries') IF binary > 0 THEN DO BINARY_GROUPS = BINARY_GROUPS + 1 BINARY_NAME.BINARY_GROUPS = GROUP_NAME.k END END /* Ask user for group to post to */ GROUP_LIST = '' DO l=1 to BINARY_GROUPS GROUP_LIST = GROUP_LIST||BINARY_NAME.l '|' END GROUP_CROSS_1 = GROUP_LIST||'Other' GROUP_LIST = GROUP_LIST||'Cross Post |Other' group_number = RTEZREQUEST('Select group to post to:',GROUP_LIST) IF group_number = 0 THEN DO group = RTGETSTRING(,group_text,title,,) IF rtresult = 0 THEN EXIT END IF group_number = BINARY_GROUPS + 1 THEN DO group_cross_number = RTEZREQUEST('Select first group to cross post to:',GROUP_CROSS_1) IF group_cross_number = 0 THEN DO group = RTGETSTRING(,group_text,title,,) IF rtresult = 0 THEN EXIT group_cross_number_2 = RTEZREQUEST('Select second group to post to:',GROUP_CROSS_1) IF group_cross_number_2 = 0 THEN DO group = group||',' RTGETSTRING(,group_text,title,,) IF rtresult = 0 THEN EXIT END ELSE group = group||',' BINARY_NAME.group_cross_number_2 END ELSE DO group = BINARY_NAME.group_cross_number DO s = 1 to BINARY_GROUPS - 1 IF s ~= group_cross_number THEN BINARY_NAME.s = BINARY_NAME.s ELSE DO t = s + 1 BINARY_NAME.s = BINARY_NAME.t END END GROUP_LIST_2 = '' DO u = 1 to BINARY_GROUPS - 1 GROUP_LIST_2 = GROUP_LIST_2||BINARY_NAME.u '|' END GROUP_LIST_2 = GROUP_LIST_2||'Other' group_cross_number_2 = RTEZREQUEST('Select second group to post to:',GROUP_LIST_2) IF group_cross_number_2 = 0 THEN DO group = group||',' RTGETSTRING(,group_text,title,,) IF rtresult = 0 THEN EXIT END ELSE group = group||',' BINARY_NAME.group_cross_number_2 END END ELSE group = BINARY_NAME.group_number /* Ask whether single part posts or multipart posts */ multipart = RTEZREQUEST('Select type of post:','Single Part|Multi Part',title) IF multipart = 1 THEN DO /* Ask user for subject */ subject = RTGETSTRING(,subject_text,title,ok_buttons,) /* Ask user for body text */ body = RTGETSTRING(,body_text,title,ok_buttons,) /* Wrap body text to 78 columns */ body. = '' EndPos = length(body); WrapPos = 1 DO n = 1 while EndPos <= length(body) EndPos = lastpos(' ',body' ', WrapPos + 79) body.n = substr(body, WrapPos, EndPos-WrapPos) WrapPos = EndPos + 1 end body.0 = n-1 /* Ask user for MIME type setting (default Image/JPEG) */ mime_type = RTGETSTRING('Image/JPEG',mime_text,title,ok_buttons,) IF rtresult = 0 THEN mime_type = 'Image/JPEG' /* Ask user if they want to post Contact Sheets (Thumbnail Indexes) */ contacts = rtezrequest(contact_query,y_or_n_buttons,title,'rtez_defaultresponse = 0') IF contacts = 1 THEN DO call rtfilerequest(default_binary_path,,contact_text, , "rtfi_flags=freqf_multiselect",contactimages) /* Base64 encode Contact Sheets */ DO o=1 to contactimages.count ADDRESS COMMAND base64_path '"'||contactimages.o||'"' '"'||temp_path||contactimagestext.o||'"' base64_args '>NIL:' DivPos = Max(lastpos(':', contactimages.o), lastpos('/', contactimages.o)) +1 contactimagename.o = substr(contactimages.o, DivPos) /* Find file length */ 'run >nil: list "'||contactimages.o||'" LFORMAT %L to pipe:size'||o ADDRESS (NEWS_PORT) IF OPEN('FileSize', 'pipe:size'||o, 'R') THEN contactbytes.o = READLN('FileSize') CLOSE('FileSize') END END /* Ask user to select binary files (jpegs) to be posted */ call rtfilerequest(default_binary_path,,files_text, , "rtfi_flags=freqf_multiselect",images) IF images = 0 THEN EXIT /* Base64 encode binary files */ DO m=1 to images.count ADDRESS COMMAND base64_path '"'||images.m||'"' '"'||temp_path||imagestext.m||'"' base64_args '>NIL:' DivPos = Max(lastpos(':', images.m), lastpos('/', images.m)) +1 imagename.m = substr(images.m, DivPos) /* Find file length */ 'run >nil: list "'||images.m||'" LFORMAT %L to pipe:size'||m ADDRESS (NEWS_PORT) IF OPEN('FileSize', 'pipe:size'||m, 'R') THEN bytes.m = READLN('FileSize') CLOSE('FileSize') END /* **** CONTACT SHEETS **** */ /* Set up MIME header for each file */ IF contacts = 1 THEN DO DO p = 1 to contactimages.count OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'W') WRITELN('CNT-Temp'||p, 'This is a multi-part message in MIME format.') WRITELN('CNT-Temp'||p, '--NewsRog-Boundary-2000') WRITELN('CNT-Temp'||p, 'Content-Type: Text/Plain; Charset=ISO-8859-1') WRITELN('CNT-Temp'||p, 'Content-Transfer-Encoding: 7Bit') WRITELN('CNT-Temp'||p, '') CLOSE('CNT-Temp'||p) /* Add body text to message */ OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'A') DO r = 1 to body.0 WRITELN('CNT-Temp'||p, body.r) END WRITELN('CNT-Temp'||p, '') WRITELN('CNT-Temp'||p, contactimagename.p) WRITELN('CNT-Temp'||p, '(Contact Sheet '||p 'of' contactimages.count||')') WRITELN('CNT-Temp'||p, '') CLOSE('CNT-Temp'||pi) /* Add signature to message */ OPEN('Sig', sig_path, 'R') OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'A') DO UNTIL EOF('Sig') sig_line = READLN('Sig') WRITELN('CNT-Temp'||p, sig_line) END CLOSE('Sig') CLOSE('CNT-Temp'||p) /* Add intermediatary MIME information */ OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'A') WRITELN('CNT-Temp'||p, '--NewsRog-Boundary-2000') WRITELN('CNT-Temp'||p, 'Content-Disposition: Inline; filename='||contactimagename.p) WRITELN('CNT-Temp'||p, 'Content-Type:' mime_type||'; name='||contactimagename.p) WRITELN('CNT-Temp'||p, 'Content-Transfer-Encoding: Base64') WRITELN('CNT-Temp'||p, '') CLOSE('CNT-Temp'||p) /* Insert Base64 Encoded Data */ OPEN('ContactImage', temp_path||contactimagestext.p, 'R') OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'A') DO UNTIL EOF('ContactImage') contactimage_line = READLN('ContactImage') WRITELN('CNT-Temp'||p, contactimage_line) END CLOSE('ContactImage') CLOSE('CNT-Temp'||p) /* Add closing MIME information */ OPEN('CNT-Temp'||p, temp_path||'CNT-Temp'||p, 'A') WRITELN('CNT-Temp'||p, '--NewsRog-Boundary-2000') CLOSE('CNT-Temp'||p) /* Add Contact Sheet posts to queue */ ADDPOST POSTNUMBER = result /* Set post group */ POSTCMD POSTNUMBER SETGROUPS group /* Set post subject */ POSTCMD POSTNUMBER SETSUBJ subject ' - Contact Sheet' p 'of' contactimages.count '('||contactbytes.p 'bytes)' POSTCMD POSTNUMBER INSFILE temp_path||'CNT-Temp'||p /* Clean up temp location */ ADDRESS COMMAND 'run >NIL: delete' temp_path||contactimagestext.p 'run >NIL: delete' temp_path||'CNT-Temp'||p ADDRESS (NEWS_PORT) END END /* **** FILES **** */ /* Set up MIME header for each file */ DO i = 1 to images.count OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'W') WRITELN('MSG-Temp'||i, 'This is a multi-part message in MIME format.') WRITELN('MSG-Temp'||i, '--NewsRog-Boundary-2000') WRITELN('MSG-Temp'||i, 'Content-Type: Text/Plain; Charset=ISO-8859-1') WRITELN('MSG-Temp'||i, 'Content-Transfer-Encoding: 7Bit') WRITELN('MSG-Temp'||i, '') CLOSE('MSG-Temp'||i) /* Add body text to message */ OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'A') DO q = 1 to body.0 WRITELN('MSG-Temp'||i, body.q) END WRITELN('MSG-Temp'||i, '') WRITELN('MSG-Temp'||i, imagename.i) WRITELN('MSG-Temp'||i, '(Image '||i 'of' images.count||')') WRITELN('MSG-Temp'||i, '') CLOSE('MSG-Temp'||i) /* Add signature to message */ OPEN('Sig', sig_path, 'R') OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'A') DO UNTIL EOF('Sig') sig_line = READLN('Sig') WRITELN('MSG-Temp'||i, sig_line) END CLOSE('Sig') CLOSE('MSG-Temp'||i) /* Add intermediatary MIME information */ OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'A') WRITELN('MSG-Temp'||i, '--NewsRog-Boundary-2000') WRITELN('MSG-Temp'||i, 'Content-Disposition: Inline; filename='||imagename.i) WRITELN('MSG-Temp'||i, 'Content-Type:' mime_type||'; name='||imagename.i) WRITELN('MSG-Temp'||i, 'Content-Transfer-Encoding: Base64') WRITELN('MSG-Temp'||i, '') CLOSE('MSG-Temp'||i) /* Insert Base64 Encoded Data */ OPEN('Image', temp_path||imagestext.i, 'R') OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'A') DO UNTIL EOF('Image') image_line = READLN('Image') WRITELN('MSG-Temp'||i, image_line) END CLOSE('Image') CLOSE('MSG-Temp'||i) /* Add closing MIME information */ OPEN('MSG-Temp'||i, temp_path||'MSG-Temp'||i, 'A') WRITELN('MSG-Temp'||i, '--NewsRog-Boundary-2000') CLOSE('MSG-Temp'||i) /* Add posts to queue */ ADDPOST POSTNUMBER = result /* Set post group */ POSTCMD POSTNUMBER SETGROUPS group /* Set post subject */ POSTCMD POSTNUMBER SETSUBJ subject ' - ' imagename.i '('||bytes.i 'bytes)' POSTCMD POSTNUMBER INSFILE temp_path||'MSG-Temp'||i /* Clean up temp location */ ADDRESS COMMAND 'run >NIL: delete' temp_path||imagestext.i 'run >NIL: delete' temp_path||'MSG-Temp'||i ADDRESS (NEWS_PORT) END END /* Multi Part files */ ELSE DO /* Check for file splitter */ IF ~EXISTS(split_path) THEN CALL split_path_error() part_size = RTGETSTRING(,'Enter size of parts (in kb):',title) part_size = part_size * 1024 /* Ask user for subject */ subject = RTGETSTRING(,subject_text,title,ok_buttons,) /* Ask user for body text */ body = RTGETSTRING(,body_text,title,ok_buttons,) /* Wrap body text to 78 columns */ body. = '' EndPos = length(body); WrapPos = 1 DO n = 1 while EndPos <= length(body) EndPos = lastpos(' ',body' ', WrapPos + 79) body.n = substr(body, WrapPos, EndPos-WrapPos) WrapPos = EndPos + 1 end body.0 = n-1 /* Ask user for MIME type setting (default Image/JPEG) */ mime_type = RTGETSTRING('Image/JPEG',mime_text,title,ok_buttons,) IF rtresult = 0 THEN mime_type = 'Image/JPEG' /* Request files */ call rtfilerequest(default_binary_path,,files_text, , "rtfi_flags=freqf_multiselect",files) IF files = 0 THEN EXIT /* Enter loop */ DO v=1 to files.count ADDRESS COMMAND DivPos = Max(lastpos(':', files.v), lastpos('/', files.v)) +1 filename.v = substr(files.v, DivPos) split_path '"'||files.v||'" S='||part_size '"'||temp_path||filename.v||'.0" >NIL:' /* Determine part names */ 'run >nil: list "'||temp_path||filename.v||'.0#?" quick files nohead to pipe:filepartlist' ADDRESS (NEWS_PORT) w=1 OPEN('fileparts','pipe:filepartlist','r') DO UNTIL EOF('fileparts') file_part_name_reversed.w = READLN('fileparts') w=w+1 END CLOSE('fileparts') part_total = w-2 /* Put file names in correct order */ b = 1 DO a = part_total to 1 by -1 file_part_name.b = file_part_name_reversed.a b=b+1 END /* Determine sizes of parts */ ADDRESS (NEWS_PORT) DO z = 1 to part_total ADDRESS COMMAND base64_path '"'||temp_path||file_part_name.z||'"' '"'||temp_path||file_part_text.z||'"' base64_args '>NIL:' 'run >nil: list "'||temp_path||file_part_name.z||'" LFORMAT %L to pipe:size'||z 'delete >nil: "'||temp_path||file_part_name.z||'"' ADDRESS (NEWS_PORT) IF OPEN('FileSize', 'pipe:size'||z, 'R') THEN bytes.z = READLN('FileSize') CLOSE('FileSize') /* Create posts */ /* Renumber file name, as .00 is used by some programs as a batch file */ IF z > 99 THEN number=z IF z < 10 THEN number='00'||z ELSE number='0'||z OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'W') WRITELN('MSG-Temp'||z, 'This is a multi-part message in MIME format.') WRITELN('MSG-Temp'||z, '--NewsRog-Boundary-2000') WRITELN('MSG-Temp'||z, 'Content-Type: Text/Plain; Charset=ISO-8859-1') WRITELN('MSG-Temp'||z, 'Content-Transfer-Encoding: 7Bit') WRITELN('MSG-Temp'||z, '') CLOSE('MSG-Temp'||z) /* Add body text to message */ OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'A') DO q = 1 to body.0 WRITELN('MSG-Temp'||z, body.q) END WRITELN('MSG-Temp'||z, '') WRITELN('MSG-Temp'||z, filename.v||'.'||number) WRITELN('MSG-Temp'||z, '(Multi Part file. Part '||z 'of' part_total||')') WRITELN('MSG-Temp'||z, '') CLOSE('MSG-Temp'||i) /* Add signature to message */ OPEN('Sig', sig_path, 'R') OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'A') DO UNTIL EOF('Sig') sig_line = READLN('Sig') WRITELN('MSG-Temp'||z, sig_line) END CLOSE('Sig') CLOSE('MSG-Temp'||z) /* Add intermediatary MIME information */ OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'A') WRITELN('MSG-Temp'||z, '--NewsRog-Boundary-2000') WRITELN('MSG-Temp'||z, 'Content-Disposition: Inline; filename='||filename.v||'.'||number) WRITELN('MSG-Temp'||z, 'Content-Type:' mime_type||'; name='||filename.v||'.'||number) WRITELN('MSG-Temp'||z, 'Content-Transfer-Encoding: Base64') WRITELN('MSG-Temp'||z, '') CLOSE('MSG-Temp'||z) /* Insert Base64 Encoded Data */ OPEN('Part', temp_path||file_part_text.z, 'R') OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'A') DO UNTIL EOF('Part') part_line = READLN('Part') WRITELN('MSG-Temp'||z, part_line) END CLOSE('Part') CLOSE('MSG-Temp'||z) /* Add closing MIME information */ OPEN('MSG-Temp'||z, temp_path||'MSG-Temp'||z, 'A') WRITELN('MSG-Temp'||z, '--NewsRog-Boundary-2000') CLOSE('MSG-Temp'||z) ADDRESS COMMAND 'delete >nil: "'||temp_path||file_part_text.z||'"' ADDRESS (NEWS_PORT) /* Add posts to queue */ ADDPOST POSTNUMBER = result /* Set post group */ POSTCMD POSTNUMBER SETGROUPS group /* Set post subject */ POSTCMD POSTNUMBER SETSUBJ subject ' - ' filename.v '- Multi Part File ('||bytes.z 'bytes) ('||z||'/'||part_total||')' POSTCMD POSTNUMBER INSFILE temp_path||'MSG-Temp'||z /* Clean up temp location */ ADDRESS COMMAND 'run >NIL: delete' temp_path||'MSG-Temp'||z ADDRESS (NEWS_PORT) END END END /* Ask user if they want to post now or later */ post_later = RTEZREQUEST(post_query,'Post Now|Post Later',title,'rtez_defaultresponse = 0') IF post_later = 0 THEN EXIT ISONLINE online = result IF online = 1 THEN DO SENDPOST ALL EXIT END go_online = RTEZREQUEST(online_query,'Go Online Now|Post Later',title) IF go_online = 0 THEN EXIT ONLINE call DELAY(250) /* Cause script to pause to allow NewsRog time to go online */ ISONLINE online2 = result IF online2 = 1 THEN DO SENDPOST ALL EXIT END call RTEZREQUEST(offline_text,'Post Later',title) END /* End program */ EXIT /* Create function() library_error */ library_error: DO ADDRESS COMMAND 'C:RequestChoice PUBSCREEN="Workbench" TITLE="Binary Batch Post by Duncan Taylor (21-Jul-2001)" BODY=" Could not execute Arexx script. *n Please check you have rexxreqtools.library *n and rexxsupport.library installed in Libs:" GADGETS="OK" >NIL:' EXIT END RETURN newsrog_path_error: DO CALL RTEZREQUEST(newsrog_path 'not found. Please configure this script','Quit',title) EXIT END RETURN temp_path_error: DO CALL RTEZREQUEST(temp_path 'not found. Please configure this script','Quit',title) EXIT END RETURN base64_path_error: DO NL='0A'x CALL RTEZREQUEST(base64_path 'not found. A Base64 Encoder is required for this script.'|| NL || 'A Base64 Encoder can be found on Aminet (/comm/mail/Base64Coders.lha)','Quit',title) EXIT END RETURN split_path_error: DO NL='0A'x CALL RTEZREQUEST(split_path 'not found. A File Splitter is required for Multi Part posts.'|| NL || 'A File Splitter can be found on Aminet (/util/cli/MrSPLIT.lha)','Quit',title) EXIT END RETURN